import { _decorator, Component, Node } from 'cc';
import StorageManager from '../Data/StorageManager';
const { ccclass, property } = _decorator;

@ccclass('AudioSoundManger')
export class AudioSoundManger extends Component {
    @property(Node) musicOff: Node = null;
    @property(Node) musicOn: Node = null;

    protected onLoad(): void {
        if (this.node.name == "Music") {
            this.musicOn.active = StorageManager.instance.music;
            this.musicOff.active = !StorageManager.instance.music;
        } else if (this.node.name == "Sound") {
            this.musicOn.active = StorageManager.instance.sound;
            this.musicOff.active = !StorageManager.instance.sound;
        }
    }
    protected onDisable(): void {
    }
    start() {

    }

    update(deltaTime: number) {

    }

    // touchStart() {
    //     this.node.setScale(.9, .9);
    // }
    // touchEnd() {
    //     this.node.setScale(1, 1);
    //     StorageManager.instance.music = !StorageManager.instance.music;
    //     StorageManager.instance.music ? this.musicOn.active = true : this.musicOff.active = true;
    // }

    changeMusic() {
        StorageManager.instance.music = !StorageManager.instance.music;
        this.musicOn.active = StorageManager.instance.music
        this.musicOff.active = !StorageManager.instance.music;

        // 发射事件
        (window as any).GlobalEventTarget.emit("changeMusic");
    }

    changeSound() {
        console.log("音效");
        
        StorageManager.instance.sound = !StorageManager.instance.sound;
        this.musicOn.active = StorageManager.instance.sound;
        this.musicOff.active = !StorageManager.instance.sound;
        
        // // 发射事件
        // (window as any).GlobalEventTarget.emit("changeSound");
    }
}


